
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>活动投屏-{php echo !empty($theme['USERCOMPANYNAME'])?$theme['USERCOMPANYNAME']:$_G['companyname'];}</title>
	<link rel="stylesheet" type="text/css" href="{$_G['URL']['WORKER_CSS']}daping/css.css" />
	<style>
		.new-order-list>li{
			text-align:center;
		}
	</style>
</head>
<body>
	<div class="body">
		<div class="left-botton"></div>
		<div class="top-center"></div>
		<div class="botton-center"></div>
		<div class="right-botton"></div>
		<div class="left-content">
			<p class="title">{$shopname}</p>
			<p class="tuan">已报名<span id="count"></span>人</p>
			<p class="qiang">火速报名中</p>
			<img src="{$_G['URL']['WORKER_CSS']}daping/BlessingBag/qiang-botton.jpg" class="qiang-botton">
			<!-- <div>
				<p class="datetitle">活动结束倒计时</p>
				<p class="date" id="date">00:00:00</p>
			</div> -->
			<div id="duiinfo" style="color:#fff;text-align:center;font-size:30px;"></div>
		</div>
		<div class="right-content">
			<p class="new-order-title">最新定单</p>
			<ul class="new-order-list" id="new-order-list">
				
			</ul>
		</div>
	</div>
	<div style="display:none">
	    <audio id="haveorder">
	    </audio>
	    <audio id="haveorder1">
	    </audio>
	</div>

</body>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
	// Count_down(1531907160);//倒计时
	var add_time ;
	$(function(){

		BlessingBagAjax();
		setInterval(newBlessingBagAjax,2000);
	})

	function BlessingBagAjax(){
		var url="/{php echo createMobileUrl('w_daping',array("themeid"=>$themeid,"company"=>$company,"op"=>'get'));}";
		$.ajax({
			url:url,
			type:'post',
			success:function(data){
				var omg = eval("("+data+")");
				if(omg.code == 200){
					console.log(omg.data);
					var list ='';
					for (var i = 0; i < omg.data.length; i++) {
						list +='<li>'+omg.data[i].babyname+''+omg.data[i].tel+''+omg.data[i].wkname+'</li>';
					}
					var dui="";
					for(var i=0;i<omg.dui.length;i++){
						dui+="<span>"+omg.dui[i].duiname+":"+omg.dui[i].counts+"单</span>      "
					}
					$('#duiinfo').html(dui);
					$("#new-order-list").html(list);
					$("#count").html(omg.cunt);
					add_time = omg.data[0].times;
				}
			}
		});
	}

	var endids=0;

	function newBlessingBagAjax(){
		var url="/{php echo createMobileUrl('w_daping',array("themeid"=>$themeid,"company"=>$company,"op"=>'get'));}";
		$.ajax({
			url:url,
			type:'post',
			data:{add_time:add_time},
			success:function(data){
				var omg = eval("("+data+")");
				if(omg.code == 200){

					var dui="";
					for(var i=0;i<omg.dui.length;i++){
						dui+="<span>"+omg.dui[i].duiname+":"+omg.dui[i].counts+"单</span>      "
					}
					$('#duiinfo').html(dui);
					console.log(omg.data);
					var countss=omg.cunt;
					$("#count").text(countss);
					var list ='';
					for (var i = 0; i < omg.data.length; i++) {

						list = list +'<li>'+omg.data[i].babyname+''+omg.data[i].tel+''+omg.data[i].wkname+'</li>';

					}

					console.log(list);
					$("#new-order-list").html(list);
					var endid=omg.data.length-1;
					add_time = omg.data[0].times;

					if(endids<omg.data[0].id){
						playordermusic(omg.data[0].babyname,omg.data[0].wkname);
						endids=omg.data[0].id;
					}


				}
			}
		})
	}

	/**
	 * 倒计时函数
	 * @param {[type]} endtime [description]
	 */
	function Count_down(endtime){
		// var starttime = 1545239993;
		var surplus = endtime-starttime;
		if(surplus > 0 ){
			var stopid = setInterval(function(){
				surplus --;
				var surplusdate = surplustime(surplus);
				$("#date").html(surplusdate);
				if(surplus == 0){
					clearInterval(stopid);
				}
			},1000);
		}
	}

	/**
	 * 剩余时间戳转时间
	 * @param  {[type]} datetime 剩余时间戳
	 * @return {[type]}          [description]
	 */
	function surplustime(surplustime){

		var h = surplustime/3600;
		var i = (surplustime%3600)/60;
		var s = surplustime%3600%60;
			h = parseInt(h);
			i = parseInt(i);
		if(h.toString().length == 1){
			h = "0"+h;
		}
		if(i.toString().length == 1){
			i = "0"+i;
		}
		if(s.toString().length == 1){
			s = "0"+s;
		}
		return h+":"+i+":"+s;
	}

	/**
	 * 时间戳转时间
	 * @param  {[type]} timeStamp 时间戳
	 * @return {[type]}           YYYY-mm-dd HH:ii:ss
	 */
	function formatDateTime(timeStamp) { 
		var date = new Date()
	    date.setTime(timeStamp * 1000);
	    var y = date.getFullYear();    
	    var m = date.getMonth() + 1;    
	    m = m < 10 ? ('0' + m) : m;    
	    var d = date.getDate();    
	    d = d < 10 ? ('0' + d) : d;    
	    var h = date.getHours();  
	    h = h < 10 ? ('0' + h) : h;  
	    var minute = date.getMinutes();  
	    var second = date.getSeconds();  
	    minute = minute < 10 ? ('0' + minute) : minute;    
	    second = second < 10 ? ('0' + second) : second;   
	    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
	};

	function playordermusic(lastordername,lastorderyg){
        var text=lastorderyg+"您的客户"+lastordername+"刚刚下了单，请及时处理！";

        var music1 = "http://{$_SERVER['HTTP_HOST']}{$_G['URL']['WORKER_CSS']}daping/ordermusic.mp3";
        var music2="http://test.wanfuwa.com.cn/alitts.php?content="+text;
        var audio1=$('#haveorder')[0];
        $(audio1).attr('src',music1);
        audio1.play();
        audio1.addEventListener("ended", function(){
//            alert('over!');
            var audio2=$('#haveorder1')[0];
            $(audio2).attr('src',music2);
            audio2.play();
        });


        var audio=$('#haveorder')[0];
        audio.play();
    }
</script>

</html>